package team.epos.merchant.service;

import team.epos.merchant.dao.DishesDao;
import team.epos.utils.pojo.Dishes;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

/**
 * Create by DishesServiceImpl on 7/13/2018
 * 菜品管理
 *
 * @author CHENKI
 */
public class DishesServiceImpl implements DishesService {
    private DishesDao dishesDao = new DishesDao();

    @Override
    public List findAllDishes(Integer id) {
        List resList = new ArrayList<Dishes>();
        TreeMap<String, Object> param = new TreeMap<>();
        param.put("sId", id);
        resList = dishesDao.getByCondition(Dishes.class, param);
        return resList;
    }

    @Override
    public List findAllDishesWithPage(Integer id, int pageIndex, int pageCount) {
        List resList = new ArrayList<Dishes>();
        TreeMap<String, Object> param = new TreeMap<>();
        param.put("sId", id);
        resList = dishesDao.getByConditionWithPage(Dishes.class, param, pageIndex, pageCount);
        return resList;
    }

    @Override
    public int addDishes(Dishes dishes) {
        int i = 0;
        i = dishesDao.insert(dishes, "seqDishes");
        return i;
    }

    @Override
    public int deleteDishes(int id) {
        int i = 0;
        i = dishesDao.deleteById(Dishes.class, id);
        return i;
    }

    @Override
    public List loadDishes(String name, int id) {
        List resList = new ArrayList<Dishes>();
        TreeMap<String, Object> param = new TreeMap<>();
        param.put("name", name);
        param.put("sId", id);
        resList = dishesDao.getByCondition(Dishes.class, param);
        return resList;
    }

    @Override
    public List loadDishesWithPage(String name, int id, int pageIndex, int pageCount) {
        List resList = new ArrayList<Dishes>();
        TreeMap<String, Object> param = new TreeMap<>();
        param.put("name", name);
        param.put("sId", id);
        resList = dishesDao.getByConditionWithPage(Dishes.class, param, pageIndex, pageCount);
        return resList;
    }

    @Override
    public int upodateDishe(Dishes dishes) {
        int i = 0;
        i = dishesDao.updateByCondition(dishes);
        return i;
    }


}
